<template>
  <div class="my-tag">
    <input
      @keydown.enter="changeTag"
      v-model="tagName"
      @blur="flag = false"
      v-focus
      v-if="flag"
      class="input"
      type="text"
      placeholder="输入标签"
    />
    <div @dblclick="tagShow" v-else class="text">{{ value }}</div>
  </div>
</template>

<script>
export default {
  name: "MyTag",
  props: {
    value: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      flag: false,
      tagName: "",
    };
  },
  methods: {
    changeTag() {
      this.flag = false;
      this.$emit("input", this.tagName);
    },
    tagShow() {
      this.flag = true;
      this.tagName = this.value;
    },
  },
};
</script>

<style lang="less" scoped>
.my-tag {
  cursor: pointer;
  .input {
    appearance: none;
    outline: none;
    border: 1px solid #ccc;
    width: 100px;
    height: 40px;
    box-sizing: border-box;
    padding: 10px;
    color: #666;
    &::placeholder {
      color: #666;
    }
  }
}
</style>